import pymysql

db = pymysql.connect(
    host="localhost",
    user="root",
    password="XingFenDe2014",
    port=3306,
    db="pythondb",
    charset="utf8"
)
# 开启mysql的游标功能，创建一个游标对象；
cursor = db.cursor()
# 要执行的SQL语句，确保数据表中有相应的数据
# name =  "admin"
# sql = 'select * from user where username = "'+name+'" '
# sql = "select * from user where username = %s"
# sql = "select * from user "
# 使用游标对象执行SQL语句；
# cursor.execute(sql,name)
# #多条数据
# data = cursor.fetchall()
# if data:
#     print(data)
# 断开数据库的连接，释放资源；
sql = "select * from record_score order by score desc "
cursor.execute(sql)
data = cursor.fetchall()
# list1 =  []
# if data:
#     # list1.append(data)
#
#     print(data)
# print(dict(data[0]))
list_username = []
list_score = []
for row in data:
        # username = row[0]
        # score = row[1]
        # major = row[2]
        # id = row[3]
        # 打印结果
        # print("myname=%s,grade=%s,major=%s,id=%s" % \
        #       (myname, grade, major, id))
        list_username.append(row[0])
        list_score.append(row[1])
print(list_username)
print(list_score)
# print(list1)
# fistname = list1[0]
# print(fistname)
db.close()
